<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>文章待审核列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="/admin/console/page">首页</a>
        <a><cite>文章待审核列表</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <%if(array.contain(session.authContext.permissionPath,"/admin/save/article")){%>
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="xadmin.open('创建文章','/admin/save/article',900,500)"><i
                            class="fa fa-plus"></i>创建文章
                    </button>
                </div>
                <%}%>
                <div class="layui-card-body ">
                    <table id="postList" lay-filter="postList"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>


<script type="text/html" id="toolbarDemo">
    <input class="text" style="height:30px;width:157px;" name="title" id="title" placeholder="请输入标题">
    <a href="#" lay-filter="" style="position: absolute;left: 144px;" onclick="searchTitle()">
        <i class="layui-icon layui-icon-search" style="background:#fff;padding:5px;"></i>
    </a>
</script>

<script type="text/html" id="operation">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-warm" lay-event="view"> 查看</button>
        <button class="layui-btn layui-btn-normal" lay-event="pass"> 同意</button>
        <button class="layui-btn layui-btn-danger" lay-event="reject">驳回</button>
    </div>
</script>

<script type="text/html" id="triggerTpl">
    {{# if(d.trigger=='create'){ }}
    新建
    {{# } else if(d.trigger=='update'){ }}
    更新
    {{# }else{ }}
    未知
    {{# } }}
</script>


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<script>
    layui.use('table', function () {
        var table = layui.table;

        table.render({
            toolbar: '#toolbarDemo',
            elem: '#postList',
            url: '/post/audit/list',
            page: true,
            cols: [[
                {field: 'id', hide: true},
                {field: 'ename', width: 80, hide: true},
                {field: 'shamId', width: 80, hide: true},
                {field: 'title', width: 280, title: "标题", sort: true},
                {field: 'trigger', width: 80, title: "类型", sort: true, templet: '#triggerTpl'},
                {field: 'userCname', width: 100, title: "修改人", sort: true},
                {
                    field: 'lastModifiedTime',
                    width: 170,
                    title: '更新时间',
                    templet: "<div>{{layui.util.toDateString(d.lastModifiedTime, 'yyyy年MM月dd日 HH:mm:ss')}}</div>"
                },
                {field: '', title: "操作", templet: '#operation'}

            ]]
        });

        table.on('tool(postList)', function (data) {

            var item = data.data;
            var ename = item.ename;
            var shamId = item.shamId;

            switch (data.event) {
                case 'view':
                    layer.open({
                        title: '查看文章',
                        type: 2,
                        shadeClose: true,
                        maxmin: true,
                        area: ['900px', '500px'],
                        content: '/admin/settings/article/detail/' + ename + '/' + shamId
                    });
                    return;
                case 'pass':
                    layer.prompt({title: '同意', formType: 2}, function (text, index) {
                        layer.close(index);
                        complete('pass', text);
                    });
                    return;
                case 'reject':

                    layer.prompt({title: '驳回', formType: 2}, function (text, index) {
                        layer.close(index);
                        complete('reject', text);
                    });
                    return;
            }

            function complete(status, reason) {
                $.ajax({
                    cache: false,
                    type: "POST",
                    contentType: 'application/json',
                    url: "/post/audit/" + ename + "/" + shamId,
                    dataType: "json",
                    data: JSON.stringify({
                        "status": status,
                        "reason": reason
                    }),
                    async: false,
                    success: function (data) {
                        if (data.code === 0) {
                            layui.table.reload('postList');
                        } else {
                            layer.msg(data.message);
                        }
                    },
                    error: function (data) {
                        layer.msg(data.message);
                    }
                });
            }


        });
    });


</script>

<script type="text/javascript">

    function searchTitle() {
        debugger;
        var title = $("#title").val();
        layui.table.reload('postList', {
            page: {
                curr: 1
            }
            , where: {
                title: title
            }
        });
    }

</script>
</html>